# yaml文件的读取与写入
import yaml


# filename采用绝对路径

# 写入yaml文件
def write_yaml(filename, data):
    # 打开filename文件、追加写、编码格式为utf-8
    with open(file=filename, mode="a", encoding="utf-8") as f:
        yaml.safe_dump(data=data, stream=f)


# 读取yaml文件
def read_yaml(filename):
    with open(file=filename, mode="r", encoding="utf-8") as f:
        return yaml.safe_load(f)


# 清空yaml文件
def clear_yaml(filename):
    with open(file=filename, mode="w", encoding="utf-8") as f:
        f.truncate()